# Sometimes using a slider is more natural for providing input than simply providing a number or using a spin box.
# For example, in the selection of shades of colors, a slider is more natural.

import sys
from PySide import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()

        slider1 = QtGui.QSlider(QtCore.Qt.Horizontal, self) # Make a horizontal slider
        slider1.setFocusPolicy(QtCore.Qt.NoFocus)
        slider1.setGeometry(30, 10, 200, 30)
        # Assigning the valueChanged signal to the userDefined changeValue() method
        slider1.valueChanged[int].connect(self.changeValue)

        self.label = QtGui.QLabel(self)
        self.label.setPixmap(QtGui.QPixmap('volume_muted.png').scaled(50, 50))
        self.label.setGeometry(160, 40, 50, 50)

        # This is how we can scale a pixmap to our desired size
        self.label1 = QtGui.QLabel(self)
        pxmp = QtGui.QPixmap('volume_muted.png')
        self.label1.setPixmap(pxmp.scaled(50, 50))
        self.label1.setGeometry(30, 70, 130, 130)

        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle("Sliders")

    def changeValue(self, value):
        if value == 0:
            self.label.setPixmap(QtGui.QPixmap('volume_muted.png').scaled(50, 50))
        if value > 0 and value < 30:
            self.label.setPixmap(QtGui.QPixmap('volume_low.png').scaled(50, 50))
        if value > 30 and value < 80:
            self.label.setPixmap(QtGui.QPixmap('volume_medium.png').scaled(50, 50))
        elif value > 80:
            self.label.setPixmap(QtGui.QPixmap('volume_high.png').scaled(50, 50))


if __name__ == "__main__":
        appObject = QtGui.QApplication(sys.argv)
        ex = Window()
        ex.show()
        sys.exit(appObject.exec_())


#import sys
#from PySide import QtGui, QtCore
#
#class Example(QtGui.QWidget):
#
#    def __init__(self):
#        super(Example, self).__init__()
#
#        self.initUI()
#
#    def initUI(self):
#
#        sld = QtGui.QSlider(QtCore.Qt.Horizontal, self)
#        sld.setFocusPolicy(QtCore.Qt.NoFocus)
#        sld.setGeometry(30, 40, 100, 30)
#        sld.valueChanged[int].connect(self.changeValue)
#
#        self.label = QtGui.QLabel(self)
#        self.label.setPixmap(QtGui.QPixmap('volume_muted.png'))
#        self.label.setGeometry(160, 40, 80, 30)
#
#        self.setGeometry(300, 300, 280, 170)
#        self.setWindowTitle('QtGui.QSlider')
#        self.show()
#
#    def changeValue(self, value):
#
#        if value == 0:
#            self.label.setPixmap(QtGui.QPixmap('volume_muted.png'))
#        elif value > 0 and value <= 30:
#            self.label.setPixmap(QtGui.QPixmap('volume_low.png'))
#        elif value > 30 and value < 80:
#            self.label.setPixmap(QtGui.QPixmap('volume_medium.png'))
#        else:
#            self.label.setPixmap(QtGui.QPixmap('volume_high.png'))
#
#def main():
#
#    app = QtGui.QApplication(sys.argv)
#    ex = Example()
#    sys.exit(app.exec_())
#
#if __name__ == '__main__':
#    main()
